#include <string.h>
#include <stdio.h>
#define NAME_LENGTH 20
#define PHONE_LENGTH 20
#define ADDRESS_LENGTH 20
#define NO_RESULT "\0"
static char name[NAME_LENGTH][20],phone[NAME_LENGTH][20],address[NAME_LENGTH][20];
static int position = -1;
void add(char const*n,char const*p,char const*a)
{
	if(position >= NAME_LENGTH)
	{
		return;
	}
	position++;
	strcpy(name[position],n);
	strcpy(phone[position],p);
	strcpy(address[position],a);
}
int find_index_by_name(char const*n)
{
	for(int i = 0;i <= position;i++)
	{
		if(strcmp(n,name[i]) == 0)
		{
			return i;
		}
	}
	return -1;
}
char const* find_phone_by_name(char const*n)
{
	int index = find_index_by_name(n);
	if(index >= 0)
	{
		return (char const*)phone[index];
	}
	return NO_RESULT;
}
char const* find_address_by_name(char const*n)
{
	int index = find_index_by_name(n);
	if(index >= 0)
	{
		return (char const*)address[index];
	}
	return NO_RESULT;
}
void find_user_by_name(char const*n)
{
	char const*p = find_phone_by_name(n);
	char const*a = find_address_by_name(n);
	printf("name\tphone\taddress\n");
	printf("%s\t%s\t%s\n",n,p,a);
}
void print_top(void)
{
	if(position < 0)
	{
		printf("record is empty!");
		return;
	}
	printf("name\tphone\taddress\n");
	printf("%s\t%s\t%s\n",name[position],phone[position],address[position]);
}
void print_all(void)
{
	if(position < 0)
	{
		printf("record is empty!");
		return;
	}
	printf("name\tphone\taddress\n");
	for(int i = 0;i <= position;i++)
	{
		printf("%s\t%s\t%s\n",name[i],phone[i],address[i]);	
	}
}
